﻿using Microsoft.Web.WebView2.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CryptoJSTest
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();


            this.webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted;

            this.webView.Source = new Uri($"file:////{System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test.html")}");


        }

        private void WebView_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
        {
            if (e.IsSuccess)
            {
                webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
                webView.CoreWebView2.Settings.AreDevToolsEnabled = true;
                webView.CoreWebView2.Settings.IsZoomControlEnabled = false;
                webView.CoreWebView2.Settings.IsStatusBarEnabled = false;
                webView.CoreWebView2.Settings.IsScriptEnabled = true;
            }
        }


        private async void button_Click(object sender, RoutedEventArgs e)
        {
            var result = await this.webView?.CoreWebView2?.ExecuteScriptAsync($"encrypt(\"{this.textBox.Text}\");");
            MessageBox.Show(result);

        }
        
        
    }
}
